package com.qf.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.entity.BusCar;
import com.qf.entity.JsonResult;
import com.qf.service.BusCarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author xlj
 * @date Created in 2021/11/26 16:56
 */

@RestController
@RequestMapping("busCar")
public class BusCarController {

    @Autowired
    private BusCarService busCarService;

    @RequestMapping("getAllCar")
    public JsonResult getAllCar(@RequestParam(value = "page",required = false,defaultValue = "1") Integer pageNum,
                                @RequestParam(value = "limit" ,required = false,defaultValue ="3" )Integer pageSize
                                ){

        PageHelper.startPage(pageNum,pageSize);
        List<BusCar> allCar = busCarService.getAllCar();
        PageInfo<BusCar> pageInfo = new PageInfo<BusCar>(allCar);

        JsonResult jsonResult = JsonResult.success();
        jsonResult.setCount(pageInfo.getTotal());
        jsonResult.setData(pageInfo.getList());

        return jsonResult;
    }
}
